package com.jiangxjsy.core.page;

import com.jiangxjsy.core.page.metadata.OrderItem;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * wukong-crm-master
 * 蒋胜宇
 * 2025/6/8 17:15
 */

@Data
@AllArgsConstructor
@NoArgsConstructor
public class BasePage<T> implements Serializable {
    /**
     * 查询数据列表
     */
    private List<T> list = new ArrayList<>();

    /**
     * 总数
     */
    private long totalRow = 0;

    /**
     * 每页显示条数，默认 15
     */
    private long pageSize = 15;

    /**
     * 当前页码，默认 1
     */
    private long pageNumber = 1;

    /**
     * 排序字段集合
     */
    private List<OrderItem> orders = new ArrayList<>();

    /**
     * 自动优化 count sql
     */
    private boolean optimizeCountSql = true;

    /**
     * 是否进行 count 查询
     */
    private boolean isSearchCount = true;

    /**
     * 额外数据
     */
    private Object extraData;


    public BasePage(long current, long size) {
        this(current, size, 0);
    }

    public BasePage(long current, long size, long total) {
        this(current, size, total, true);
    }

    public BasePage(long current, long size, boolean isSearchCount) {
        this(current, size, 0, isSearchCount);
    }

    public BasePage(long current, long size, long total, boolean isSearchCount) {
        if (current > 1) {
            this.pageNumber = current;
        }
        this.pageSize = size;
        this.totalRow = total;
        this.isSearchCount = isSearchCount;
    }


    public List<T> getRecords() {
        return this.list;
    }

    public BasePage<T> setRecords(List<T> records) {
        this.list = records;
        return this;
    }


    public long getSize() {
        return this.pageSize;
    }

    public BasePage<T> setSize(long size) {
        this.pageSize = size;
        return this;
    }
}
